#!/usr/bin/make -f

CFLAGS = -Wall

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

configure: configure-stamp configure-stamp-nophonon
configure-stamp:
	dh_testdir
	qmake-qt4
	touch $@
configure-stamp-nophonon:
	dh_testdir
	qmake-qt4 NO_PHONON=1
	touch $@

build: build-stamp build-stamp-nophonon
build-stamp: configure-stamp 
	dh_testdir
	$(MAKE) CFLAGS="$(CFLAGS)"
	$(MAKE) clean
	rm -f Makefile
	touch $@
build-stamp-nophonon: configure-stamp-nophonon
	dh_testdir
	$(MAKE) CFLAGS="$(CFLAGS)"
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp build-stamp-nophonon configure-stamp-nophonon
	if test -f $(CURDIR)/Makefile; then \
		$(MAKE) distclean; \
	fi
	rm -f konvid
	dh_clean

install:
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs -A usr/bin
	dh_installdirs -A usr/share/pixmaps
	dh_installdirs -A usr/share/applications
	dh_installman -A debian/konvid.1
	mv $(CURDIR)/debian/konvid-lite/usr/share/man/man1/konvid.1 $(CURDIR)/debian/konvid-lite/usr/share/man/man1/konvid-lite.1
	cp $(CURDIR)/konvid $(CURDIR)/debian/konvid/usr/bin/konvid
	cp $(CURDIR)/images/konvid.png $(CURDIR)/debian/konvid/usr/share/pixmaps/konvid.png
	cp $(CURDIR)/konvid.desktop $(CURDIR)/debian/konvid/usr/share/applications/konvid.desktop
	cp $(CURDIR)/konvid-lite $(CURDIR)/debian/konvid-lite/usr/bin/konvid-lite
	cp $(CURDIR)/images/konvid.png $(CURDIR)/debian/konvid-lite/usr/share/pixmaps/konvid-lite.png
	cp $(CURDIR)/konvid-lite.desktop $(CURDIR)/debian/konvid-lite/usr/share/applications/konvid-lite.desktop

binary-indep: build install

binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs -A debian/README.Debian
	dh_installmenu
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
